﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CF_DAL_WS.Models;

namespace CF_DAL_WS.DTO
{
    public class OrderDetailDTO
    {
        public int ID { get; set; }
        public int IDOrder { get; set; }
        public int IDFood { get; set; }
        public int Quantity { get; set; }
        public float Price { get; set; }
        public FoodDTO Food { get; set; }

        public static OrderDetailDTO Translate(OrderDetail Entity)
        {
            if (Entity != null)
            {
                var dto = new OrderDetailDTO
                {
                    ID = Entity.ID
                };
                if (Entity.IDOrder != null)
                {
                    dto.IDOrder = Entity.IDOrder.Value;
                }
                if (Entity.IDFood != null)
                {
                    dto.IDFood = Entity.IDFood.Value;
                }
                if (Entity.Quantity != null)
                {
                    dto.Quantity = Entity.Quantity.Value;
                }
                if (Entity.Price != null)
                {
                    dto.Price = Entity.Price.Value;
                }
                if (Entity.Food != null)
                {
                    dto.Food = FoodDTO.TranslateBase(Entity.Food);
                }
                return dto;
            }
            return null;
        }

        public static OrderDetail Reverse(OrderDetailDTO obj)
        {
            var entity = new OrderDetail
            {
            };
            if (obj.IDOrder != -1)
            {
                entity.IDOrder = obj.IDOrder;
            }
            if (obj.IDFood != -1)
            {
                entity.IDFood = obj.IDFood;
            }
            if (obj.Quantity != -1)
            {
                entity.Quantity = obj.Quantity;
            }
            if (obj.Price != -1)
            {
                entity.Price = obj.Price;
            }
            return entity;
        }

        public void UpdateEntity(ref OrderDetail entity)
        {
            if (IDOrder != -1)
            {
                entity.IDOrder = IDOrder;
            }
            if (IDFood != -1)
            {
                entity.IDFood = IDFood;
            }
            if (Quantity != -1)
            {
                entity.Quantity = Quantity;
            }
            if (Price != -1)
            {
                entity.Price = Price;
            }
        }
    }
}